// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// c [author] rhyme_lph
// K [email]  rhymelph@gmail.com
// G [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/entities/transaction_entity.dart';
import 'package:finance_app/src/mixin/filter_transaction_sort_mixin.dart';
import 'package:finance_app/src/mixin/refresh_mixin.dart';
import 'package:finance_app/src/mixin/search_data_list_mixin.dart';
import 'package:finance_app/src/mixin/time_sort_mixin.dart';
import 'package:finance_app/src/mixin/transaction_data_mixin.dart';
import 'package:flutter/material.dart';

import '../credit_debit_provider.dart';

class DebitNoteProvider extends BaseProvider<dynamic>
    with
        FilterTransactionSortMixin,
        TimeSortMixin,
        TransactionDataMixin,
        SearchDataListMixin,
        RefreshMixin<dynamic, List<TransactionEntity>> {
  ScrollController controller = ScrollController();

  @override
  void initState() {
    final saleP = getParentProvider<CreditDebitProvider>();
    contactId = saleP.contactId;
    super.initState();

    controller.addListener(() {
      getParentProvider<CreditDebitProvider>().handleScrollUpdate(controller);
    });
  }

  @override
  Future get dataFuture => null;

  @override
  List<TransactionEntity> get dataList => transactionList;

  @override
  List<String> get filterList => ['Fully Credited', 'Credit Available'];

  @override
  List<String> get types => ['debit_note'];
  @override
  List<String> get statusList => statusTypeList;

  List<String> get statusTypeList {
    List<String> statusResult = [];
    if (currentSelectFilterList.length > 0) {
      for (final item in currentSelectFilterList) {
        if (statusToKey.containsKey(item)) {
          statusResult.add(statusToKey[item]);
        }
      }
    }
    if (statusResult.length == 0) {
      return null;
    }
    return statusResult;
  }
}
